/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Objects;

import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author CKCantillas
 */
public class ResidencyLogAdminModel extends DefaultTableModel {
    String[] cols = {"ID No.", "LAST NAME", "LOG ID", "DATE", "LOG IN", "LOG OUT", "TOTAL(hr)", "TOTAL(min)"};
    String[][] table;
    
    private void makeTable (ResultSet rs) {
        
        try {
            ResidencyLog rl;
            int nRows = 0;
            while (rs.next()) {
                nRows++;
            }
            rs.beforeFirst();
            table = new String[nRows][cols.length];
            int i = 0;
            
            while (rs.next()) {
                rl = new ResidencyLog(
                        rs.getInt("residency_log_id"),
                        rs.getString("staffer_id"),
                        rs.getString("date"),
                        rs.getString("login"),
                        rs.getString("logout"));
                
                int j = 0;
                table[i][j++] = rs.getString("IDnumber");
                table[i][j++] = rs.getString("last_name");
                table[i][j++] = Integer.toString(rl.getResLogID());
                table[i][j++] = rl.getDate();
                table[i][j++] = rl.getTimeIn();
                table[i][j++] = rl.getTimeOut();
                table[i][j++] = Float.toString(rl.getTotalMinutes() / 60);
                table[i][j++] = Float.toString(rl.getTotalMinutes());
                
                i++;
            }
        } catch (SQLException e) {}
        
    }
    
    public ResidencyLogAdminModel(ResultSet rs) {
        makeTable(rs);
        super.setDataVector(table, cols);
    }
}
